//
//  MasterViewController.m
//  Presidents
//
//  Created by Justsoso on 16/3/10.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "MasterViewController.h"
#import "PresidentsModal.h"
#import "TableViewCell.h"

@interface MasterViewController ()

@property (nonatomic,strong) NSArray *list;

@end

@implementation MasterViewController

- (NSArray *)list
{
    if (_list == nil)
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"PresidentList" ofType:@"plist"];
        NSDictionary *tmpDict = [NSDictionary dictionaryWithContentsOfFile:path];
        NSArray *arr = tmpDict[@"presidents"];
        NSMutableArray *mArr = [NSMutableArray array];
        for (NSDictionary *dic in arr)
        {
            PresidentsModal *p = [PresidentsModal PresidentWithDict:dic];
            [mArr addObject:p];
        }
        _list = mArr;
    }
    return _list;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    PresidentsModal *presidents = self.list[indexPath.row];
    // Configure the cell...
    cell.presidents = presidents;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PresidentsModal *presidents = self.list[indexPath.row];
    NSString *url = presidents.url;
    
    self.detailVC.url = url;
}



@end
